home *** CD-ROM | disk | FTP | other *** search
/ MacFormat UK 160 - Disc 1 / MF_UK_160_1.iso / pc / DiscContent / FullSoftware / Amapi61MacEn / Amapi 3D 6.1 Installer / 3SPACE / SpinBehavior.js < prev    next >
Encoding:
Text File  |  2001-02-20  |  1.6 KB  |  66 lines  |  [AMAS/AMAP]

  1. // -* SpinBehavior.js *-
  2. //
  3. // Name: Spin behavior
  4. // Description: 
  5. // Author:
  6. // Version: $Id: SpinBehavior.js,v 1.9 2000/12/21 15:03:30 consumer Exp $
  7. //
  8.  
  9. // Keep an array of the solids using this behavior
  10. var spinSolids = new Array(1);
  11.  
  12. function SpinBehavior(solidName, axe, speed)
  13. {
  14.   // Member methods of the behavior
  15.   this.start = SpinBehaviorStart;
  16.   this.stop = SpinBehaviorStop;
  17.  
  18.   // Convert turn/mn to rad/s;
  19.   var speed = (speed * Math.PI * 2.0) / 60.0;
  20.   this.angularVelocity = TSMakeStringFromVector(TSVectorMultiply(axe, speed));
  21.   this.solidName = solidName;
  22.   this.dampingID = TSMakeUniqID("DampingForce_" + solidName);
  23. }
  24.  
  25. function SpinBehaviorStart()
  26. {
  27.   // Suppress the damping force
  28.   TSMakeDampingSolidForce(this.dampingID, 0.0, 0.0);
  29.   TSAppendChild(this.solidName, this.dampingID);
  30.   TSUpdateNode(this.dampingID);
  31.  
  32.   // Set the angular velocity
  33.   TSUpdateNodeAttribute(this.solidName, 'angularVelocity', this.angularVelocity);
  34. }
  35.  
  36. function SpinBehaviorStop()
  37. {
  38.   TSUpdateNodeAttribute(this.solidName, 'angularVelocity', '0 0 0');
  39.   TSRemoveNode(this.dampingID);
  40. }
  41.  
  42. //
  43. // Event functions
  44. //
  45.  
  46. function SpinBehaviorStartEvent(obj, event)
  47. {
  48.   if (spinSolids[obj] == null) {
  49.     var axe = TSMakeVectorFromString(TSGetExtraParam(event, 'axis'));
  50.     var speed = TSGetExtraParam(event, 'speed');
  51.     var targetSolid = TSGetExtraParam(event, 'targetSolid');
  52.  
  53.     if (targetSolid == "")
  54.       spinSolids[obj] = new SpinBehavior(obj, axe, speed);
  55.     else
  56.       spinSolids[obj] =  new SpinBehavior(targetSolid, axe, speed);
  57.   }
  58.  
  59.   spinSolids[obj].start();
  60. }
  61.  
  62. function SpinBehaviorStopEvent(obj, event)
  63. {
  64.   spinSolids[obj].stop();
  65. }
  66.